home *** CD-ROM | disk | FTP | other *** search
- 10 'NGUESS.BAS - to illustrate the 'Top Down' theory of programming
- 20 'From the GW-Basic Tutorial Series, GWBT11, 04-30-1991
- 30 '
- 40 'This program 'thinks' of a random number from 1 to 10 and asks the user
- 50 'to guess the number...
- 60 GOSUB 1000 'Randomize and set up
- 70 GOSUB 2000 'Present guess prompt and get guesses
- 80 GOSUB 3000 'See if we want to play again
- 90 END 'End of program
- 1000 'Setup and randomizing for number guess...
- 1010 RANDOMIZE (-TIMER)
- 1020 CLS
- 1030 KEY OFF
- 1040 LOCATE 3,1,0
- 1050 RETURN
- 2000 'Think of a number and get the user's guesses...
- 2010 NUMBER=INT(RND(1)*10)
- 2015 IF NUMBER=0 THEN NUMBER=1
- 2020 PRINT "I am thinking of a number between one and ten. Can you guess it"
- 2030 PRINT "within eight tries?"
- 2040 COUNTER=1
- 2050 PRINT "Guess #";COUNTER;" is:";
- 2060 INPUT GUESS
- 2070 IF GUESS = NUMBER THEN PRINT "Yes! You're correct!":RETURN
- 2080 PRINT "Nope, sorry!"
- 2090 COUNTER=COUNTER+1
- 2100 IF COUNTER=9 THEN PRINT "Sorry! The number was";NUMBER:RETURN
- 2110 GOTO 2050
- 3000 'See if we are going to play again...
- 3010 PRINT
- 3020 PRINT "Do you want to try your luck again? Yes or No."
- 3030 LINE INPUT ANSWER$
- 3040 ANSWER$=LEFT$(ANSWER$,1)
- 3050 'See if it's No
- 3060 IF ANSWER$="N" OR ANSWER$="n" THEN END
- 3070 RUN